#ifndef __Card_SPI_H
#define __Card_SPI_H

#ifdef APM32E10X_HD
	#include "apm32e10x_gpio.h"     
	#include "apm32e10x_rcm.h" 
	#include "apm32e10x_spi.h"
	
#elif defined AT32F403AVGT7
	#include "at32f403a_407_gpio.h" 
	#include "at32f403a_407_crm.h" 
	#include "at32f403a_407_spi.h" 
	
#else
	#include "apm32f10x_gpio.h"     
	#include "apm32f10x_rcm.h" 
	#include "apm32f10x_spi.h"
#endif

#include "BoardData.h"

//////////////////////// SPI 引脚上拉控制 /////////////////////////
#define  card_spi_pullup       1       // >0 使能上拉

//////////////////////// SPI 引脚 /////////////////////////

//引脚块1  
#define CardSPI_Pin_RCM             RCM_APB2_PERIPH_GPIOB                         
#define CardSPI_PinPort             GPIOB

// 重启按钮RST引脚 = PD8; 有RST引脚读数据失败。
//#define CardSPI_RST_RCM             RCM_APB2_PERIPH_GPIOD                         
//#define CardSPI_RSTPort             GPIOD
//#define CardSPI_RST_PinId           GPIO_PIN_8 

// SPI通讯
#define CardSPI_CS_PinId            GPIO_PIN_12 
#define CardSPI_SCLK_PinId          GPIO_PIN_13  
#define CardSPI_MOSI_PinId          GPIO_PIN_15  
#define CardSPI_MISO_PinId          GPIO_PIN_14  

// SPI功能
#define CardSPI_RCM                 RCM_APB1_PERIPH_SPI2
#define CardSPI_id                  SPI2

// 定义函数
#define CardSPI_bit_set(x)          CardSPI_PinPort -> BSC = x  // 置1
#define CardSPI_bit_reset(x)        CardSPI_PinPort -> BC  = x  // 置0

#ifdef CardSPI_RST_PinId
#define CardSPI_RST_High()          CardSPI_PinPort -> BSC = CardSPI_RST_PinId  // 置1
#define CardSPI_RST_Low()           CardSPI_PinPort -> BC  = CardSPI_RST_PinId  // 置0
#endif

#define RS522_NSS_0                 CardSPI_PinPort -> BC  = CardSPI_CS_PinId            
#define RS522_NSS_1                 CardSPI_PinPort -> BSC = CardSPI_CS_PinId

///// 函数声明 //////
void CardSPI_init(void);
#ifdef CardSPI_RST_PinId
void CardSPI_RST_init(void); 
#endif
uint8_t CardSPI_SendRead_Byte(uint8_t data);

#endif


